﻿#region Using Directives

using System;
using System.Web.Security;
using System.Collections.Generic;

using QuickDev.Common.Utils;
using QuickDev.Common.Serialization;

using QuickDev.Model;
using QuickDev.SQLServerDAL;
using QuickDev.Caching;

#endregion

namespace QuickDev.BLL
{
    /// <summary>
    /// BLL Layer For dbo.OPM_ReturnType.
    /// </summary>
    public class ReturnTypeBLL
    {
        #region ReturnTypeBLL.IsExist( string name )
        /// <summary>
        /// public static bool IsExist( string name )
        /// </summary>
        /// <param name="name">name</param>
        /// <returns>bool Existed</returns>
        public static bool IsExist( string name )
        {
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( name , "QuickDev.BLL.ReturnTypeBLL.IsExist() Method -- name" );

            return ReturnTypeDAL.IsExist( name );
        }

        #endregion

        #region ReturnTypeBLL.Insert( string name, string description, int displayOrder, bool published, int createdBy ) Method

        /// <summary>
        /// public static int Insert( string name, string description, int displayOrder, bool published, int createdBy )
        /// </summary>
        /// <param name="name">name</param>
        /// <param name="description">description</param>
        /// <param name="displayOrder">displayOrder</param>
        /// <param name="published">published</param>
        /// <param name="createdBy">createdBy</param>
        /// <returns>ReturnType model</returns>
        public static ReturnType Insert( string name , string description , int displayOrder , bool published , int createdBy )
        {
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( name , "QuickDev.BLL.ReturnTypeBLL.Insert() Method -- name" );
            //Validation.ValidateStringArgumentIsNotNullOrEmptyString( description , "QuickDev.BLL.ReturnTypeBLL.Insert() Method -- description" );
            Validation.ValidateIntegerIsGreaterThanZero( displayOrder , "QuickDev.BLL.ReturnTypeBLL.Insert() Method -- displayOrder" );

            int newId = ReturnTypeDAL.Insert( name , description , displayOrder , published , createdBy );

            if ( newId > 0 )
            {
                ReturnTypeCache.RemoveAllCollectionFromCache();

                return ReturnTypeCache.GetModel( newId );
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region ReturnTypeBLL.Update( int id, string name, string description, int displayOrder, bool published, int updatedBy ) Method

        /// <summary>
        /// public static bool Update( int id, string name, string description, int displayOrder, bool published, int updatedBy )
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="name">name</param>
        /// <param name="description">description</param>
        /// <param name="displayOrder">displayOrder</param>
        /// <param name="published">published</param>
        /// <param name="updatedBy">updatedBy</param>
        /// <returns>ReturnType model</returns>
        public static ReturnType Update( int id , string name , string description , int displayOrder , bool published , int updatedBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( id , "QuickDev.BLL.ReturnTypeBLL.Update() Method -- id" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( name , "QuickDev.BLL.ReturnTypeBLL.Update() Method -- name" );
            //Validation.ValidateStringArgumentIsNotNullOrEmptyString( description , "QuickDev.BLL.ReturnTypeBLL.Update() Method -- description" );
            Validation.ValidateIntegerIsGreaterThanZero( displayOrder , "QuickDev.BLL.ReturnTypeBLL.Update() Method -- displayOrder" );

            if ( ReturnTypeDAL.Update( id , name , description , displayOrder , published , updatedBy ) )
            {
                ReturnTypeCache.RemoveAllCollectionFromCache();
                ReturnTypeCache.RemoveModelFromCache( id );

                return ReturnTypeCache.GetModel( id );
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region ReturnTypeBLL.Delete( int id , int deletedBy ) Method

        /// <summary>
        /// public bool Delete( int id , int deletedBy )
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="updatedBy">updatedBy</param>
        /// <returns>bool sucessful</returns>
        public static bool Delete( int id , int deletedBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( id , "QuickDev.BLL.ReturnTypeBLL.Delete -- id" );

            if ( ReturnTypeDAL.Delete( id , deletedBy ) )
            {
                ReturnTypeCache.RemoveAllCollectionFromCache();

                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion
    }
}

